-- war_stare
-- create by chendh
-- 技能: 战争凝视

return {
    apply = function(source, target, skillId, round, para, extra)
        local dbase = MonsterM.query(source.dbase:query("class_id"), "dbase");
        local max_value = dbase["max_energy"] or 100;

        -- 判断是否能量已满
        if source.dbase:query("energy", 0) >= max_value then
            -- 判断是否有小石像
            local posList = { 11, 15, 16, 20, 21, 25, };
            local isFound = false;

            for _, pos in ipairs(posList) do
                local grid = DungeonM.getGridByPos(pos);
                -- 判断是否有怪物
                if not grid.monster then
                    isFound = true;
                    break;
                end
            end

            if isFound then
                local amount = source.dbase:query("energy", 0);

                -- 初始化序列
                SkillM.initSequence(source, target, 0);
                -- 远程怪攻击动作
                SkillM.getSequence(source):remoteAttack(source, target, para[2]);
                -- 召唤小石像，清空能量
                SkillM.apply(source, target, para[2], CombatM.getRound());

                source.dbase:set("energy", 0);

                EventMgr.fire(event.COST_ENERGY, {
                    ["amount"]  = amount,
                    ["pos"]     = source:getPos(),
                    ["attrib"]  = "energy", });

                return 0;
            end
        end

        -- 初始化序列
        SkillM.initSequence(source, target, 0);
        -- 远程怪攻击动作
        SkillM.getSequence(source):remoteAttack(source, target, para[1]);
        SkillM.apply(source, target, para[1], CombatM.getRound());

        -- 不能出现UI的东西。暂时屏蔽掉，另new任务改
        -- 抛出个场景行为事件，往场景行为序列加入"投掷"行为
        -- EventMgr.fire(event.ADD_SCENE_SEQUENCE, {
        --     ["action"]  = "launch",
        --     ["fromPos"] = UIDungeonMgr:getCurLevel():getMonsterPos(source:getOwner()),
        --     ["toPos"]   = UIDungeonMgr:getCurLevel():getHeroPos();
        --     ["args"]    = { ["skill_id"] = para[1], },
        --     });
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
}

